<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" v-auth="'order.aftersale.create'" @click="create"></el-button>
                <el-button type="danger" plain icon="el-icon-delete" v-auth="'order.aftersale.delete'" v-if="selection.length>0" :disabled="selection.length==0" @click="dels"></el-button>
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search" placeholder="搜索" @clear="this.$TABLE.searchSubmit(this)" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="this.$TABLE.searchSubmit(this)"></el-button>
                    <imiFilterBar :options="options" @filterChange="filterChange"></imiFilterBar>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" :params="params" @selection-change="selectionChange" @cell-dblclick="doubleClick" stripe remoteSort remoteFilter>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="id" prop="id" >
                                    
				</el-table-column>
                <el-table-column label="售后单号" prop="aftersale_sn" >
                                    
				</el-table-column>
                <el-table-column label="用户" prop="user_id" >
                                    
				</el-table-column>
                <el-table-column label="类型" prop="type" >
                                    
				</el-table-column>
                <el-table-column label="售后类型" prop="type_str" >
                                    
				</el-table-column>
                <el-table-column label="联系方式" prop="phone" >
                                    
				</el-table-column>
                <el-table-column label="活动" prop="activity_id" >
                                    
				</el-table-column>
                <el-table-column label="活动类型" prop="activity_type" >
                                    
				</el-table-column>
                <el-table-column label="订单" prop="order_id" >
                                    
				</el-table-column>
                <el-table-column label="订单商品" prop="order_item_id" >
                                    
				</el-table-column>
                <el-table-column label="商品" prop="goods_id" >
                                    
				</el-table-column>
                <el-table-column label="规格 id" prop="goods_sku_price_id" >
                                    
				</el-table-column>
                <el-table-column label="规格名" prop="goods_sku_text" >
                                    
				</el-table-column>
                <el-table-column label="商品名称" prop="goods_title" >
                                    
				</el-table-column>
                <el-table-column label="商品图片" prop="goods_image" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.goods_image" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="商品原价" prop="goods_original_price" >
                                    
				</el-table-column>
                <el-table-column label="优惠费用" prop="discount_fee" >
                                    
				</el-table-column>
                <el-table-column label="商品价格" prop="goods_price" >
                                    
				</el-table-column>
                <el-table-column label="购买数量" prop="goods_num" >
                                    
				</el-table-column>
                <el-table-column label="发货状态" prop="dispatch_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.dispatch_status" @change="this.$TABLE.change(scope.row.id,$event,'dispatch_status',this.$API.order_aftersale.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="发货费用" prop="dispatch_fee" >
                                    
				</el-table-column>
                <el-table-column label="售后状态" prop="aftersale_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.aftersale_status" @change="this.$TABLE.change(scope.row.id,$event,'aftersale_status',this.$API.order_aftersale.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                <el-table-column label="退款状态" prop="refund_status" >
                                    
				</el-table-column>
                <el-table-column label="买家备注" prop="ps" >
                                    
				</el-table-column>
                <el-table-column label="卖家备注" prop="memo" >
                                    
				</el-table-column>
                <el-table-column label="买家图集" prop="images" >
                                    
				</el-table-column>
                <el-table-column label="退款金额" prop="refund_fee" >
                                    
				</el-table-column>
                <el-table-column label="退款积分" prop="refund_score" >
                                    
				</el-table-column>
                <el-table-column label="退款贝壳" prop="refund_shell" >
                                    
				</el-table-column>
                <el-table-column label="添加时间" prop="createtime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="更新时间" prop="updatetime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="删除时间" prop="deletetime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="店铺id" prop="store_id" >
                                    
				</el-table-column>
                <el-table-column label="买家退快递公司" prop="express_name" >
                                    
				</el-table-column>
                <el-table-column label="买家退快递公司编号" prop="express_code" >
                                    
				</el-table-column>
                <el-table-column label="买家退快递单号" prop="express_no" >
                                    
				</el-table-column>
                <el-table-column label="店铺发快递公司" prop="store_express_name" >
                                    
				</el-table-column>
                <el-table-column label="店铺发快递公司编号" prop="store_express_code" >
                                    
				</el-table-column>
                <el-table-column label="店铺发快递单号" prop="store_express_no" >
                                    
				</el-table-column>
                <el-table-column label="联系电话" prop="store_phone" >
                                    
				</el-table-column>
                <el-table-column label="收货人" prop="consignee" >
                                    
				</el-table-column>
                <el-table-column label="详细地址" prop="address" >
                                    
				</el-table-column>
                <el-table-column label="平台状态" prop="sys_status" >
                    <template #default="scope">
                    <el-switch v-model="scope.row.sys_status" @change="this.$TABLE.change(scope.row.id,$event,'sys_status',this.$API.order_aftersale.operate)" :active-value="1" :inactive-value="0"></el-switch>
                    </template>                
				</el-table-column>
                
                <el-table-column label="操作" fixed="right" align="right" width="140">
                    <template #default="scope">
                        <el-button type="text" v-auth="'order.aftersale.update'" size="small" @click="update(scope.row)">编辑
                        </el-button>
                        <el-popconfirm title="确定删除吗？" @confirm="del(scope.row)">
                            <template #reference>
                                <el-button type="text" v-auth="'order.aftersale.delete'" size="small">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
</template>
<script>
    import saveDialog from './save';
    import imiFilterBar from '@/components/imiFilterBar';
    export default {
        name: 'order.aftersale',
        components: {
            saveDialog,
            imiFilterBar
        },
        data() {
            return {
                options: [
                    {
                        label: 'id',
                        value: 'id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '售后单号',
                        value: 'aftersale_sn',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '用户',
                        value: 'user_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '类型',
                        value: 'type',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '售后类型',
                        value: 'type_str',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '联系方式',
                        value: 'phone',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '活动',
                        value: 'activity_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '活动类型',
                        value: 'activity_type',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '订单',
                        value: 'order_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '订单商品',
                        value: 'order_item_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品',
                        value: 'goods_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '规格 id',
                        value: 'goods_sku_price_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '规格名',
                        value: 'goods_sku_text',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品名称',
                        value: 'goods_title',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品原价',
                        value: 'goods_original_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '优惠费用',
                        value: 'discount_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '商品价格',
                        value: 'goods_price',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '购买数量',
                        value: 'goods_num',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '发货状态',
                        value: 'dispatch_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '发货费用',
                        value: 'dispatch_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '售后状态',
                        value: 'aftersale_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					{
                        label: '退款状态',
                        value: 'refund_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家备注',
                        value: 'ps',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '卖家备注',
                        value: 'memo',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家图集',
                        value: 'images',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '退款金额',
                        value: 'refund_fee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '退款积分',
                        value: 'refund_score',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '退款贝壳',
                        value: 'refund_shell',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '添加时间',
                        value: 'createtime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '更新时间',
                        value: 'updatetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '删除时间',
                        value: 'deletetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '店铺id',
                        value: 'store_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家退快递公司',
                        value: 'express_name',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家退快递公司编号',
                        value: 'express_code',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '买家退快递单号',
                        value: 'express_no',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '店铺发快递公司',
                        value: 'store_express_name',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '店铺发快递公司编号',
                        value: 'store_express_code',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '店铺发快递单号',
                        value: 'store_express_no',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '联系电话',
                        value: 'store_phone',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '收货人',
                        value: 'consignee',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '详细地址',
                        value: 'address',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '平台状态',
                        value: 'sys_status',
                        type: 'select',
                        operator: '=',
                    	extend: {
                            data: [{label:"开启",value:1},{label:"关闭",value:0}]
	                    }
					},
					                    
                ],
                dialog: {
                    save: false
                },
                apiObj: this.$API.order_aftersale.read,
                selection: [],
                search: '',
                params:{},
            }
        },
        created() {
            this.$TABLE.setFilterValue(this);
        },
        mounted() {
            
        },
        methods: {
            doubleClick(row) {
                this.update(row);
            },
            filterChange(data) {
                this.$TABLE.filter(data, this);
            },
            create() {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open()
                })
            },
            update(row) {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('update').setData(row)
                })
            },
            async del(row) {
                var res = await this.$API.order_aftersale.delete.post({ids: row.id});
                if (res.code == 200) {
                    this.$refs.table.refresh()
                    this.$message.success(res.message)
                } else {
                    this.$alert(res.message, "提示", {type: 'error'})
                }
            },
            async dels() {
                if (!this.selection.length) {
                    this.$message.warning("请选择要删除的数据")
                    return false;
                }
                var ids = [];
                for (const i in this.selection) {
                    ids.push(this.selection[i].id)
                }
                this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
                    type: 'warning'
                }).then(() => {
                    const loading = this.$loading();
                    this.$API.order_aftersale.delete.post({ids:ids}).then(res => {
                        if (res.code == 200) {
                            this.$refs.table.refresh()
                            this.$message.success(res.message)
                        } else {
                            this.$message.error(res.message)
                        }
                        loading.close();
                    });
                })
            },
            selectionChange(selection) {
                this.selection = selection;
            },
            handleSuccess() {
                this.$refs.table.refresh()
            }
        }
    }
</script>